package com.yxp.offer;

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;

/**
 * @Auther : yxpweb
 * @Date : 2021/8/13 9:46
 * @Description: 剑指 Offer 30. 包含min函数的栈
 */
public class Problem30 {

    private Stack<Integer> minStack;
    private Queue<Integer> sortQueue;

    public Problem30() {
        minStack = new Stack<>();
        sortQueue = new PriorityQueue<>();
    }

    public void push(int x) {
        minStack.push(x);
        sortQueue.add(x);
    }

    public void pop() {
        Integer pop = minStack.pop();
        sortQueue.remove(pop);
    }

    public int top() {
        return minStack.peek();
    }

    public int min() {
        return sortQueue.peek();
    }
}
